package com.dongdong.controller;


import com.dongdong.service.CartService;
import com.dongdong.utils.Result;
import com.dongdong.utils.ResultEnum;
import com.dongdong.vo.CartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private CartService cartService;

    @GetMapping("/addCart")
    private Result addCart(@RequestHeader String accessToken,
                           @RequestParam Long skuId,@RequestParam Integer num){
        cartService.addCart(accessToken,skuId,num);
        return Result.DATA(ResultEnum.ADD_CART);
    }

    @GetMapping("/getCart")
    public Result getCart(@RequestHeader String accessToken){
        List<CartVO> cartVOS = cartService.getCart(accessToken);
        return Result.OK().setData(cartVOS);
    }

    @GetMapping("/getCartList")
    public List<CartVO> getCartList(@RequestHeader String accessToken){
        List<CartVO> cartVOS = cartService.getCart(accessToken);
        return cartVOS;
    }
}
